import { setToken, getToken, removeToken } from '@/utils/storage.js'
// 用户模块vuex
const state = {
  // token数据
//   tokenInfo: {}
//   tokenInfo: JSON.parse(localStorage.getItem('tokenInfo'))
  tokenInfo: getToken() || {}
}
// 存放操作数据的方法
const mutations = {
  setTokenInfo (state, tokenInfo) {
    state.tokenInfo = tokenInfo
    // 一更新token, 就往本地存一份, 本地就可以实时的同步到vuex的数据
    // localStorage.setItem('tokenInfo', JSON.stringify(tokenInfo))
    setToken(tokenInfo)
  },
  // 移除token方法
  removeTokenInfo (state) {
    state.tokenInfo = {}
    // 清除本地存储的数据
    removeToken()
  }
}
const actions = {}
const getters = {}
export default {
  state,
  mutations,
  actions,
  getters,
  namespaced: true
}
